import react,{Component} from "react";

export default class Useritem extends Component{
    state={
        is_selected:false,
        isonhandle:false
    };
    handleMouse=(flag)=>{
    return()=>{
        this.setState({isonhandle:flag})
    }}
    handleClick=(id)=>{
        return ()=>{
            this.setState({is_selected:true})
            this.props.gotoChat(id);
        }
    }
    render() {
        const user=this.props.user;
        const {now_chat_object_id}=this.props
        const id=user["id"];
        console.log("IN USERITEM, the ID:",id)
        const {is_selected,isonhandle}=this.state
        // if(this.state.is_selected){
        //     if (id!==now_chat_object_id){
        //         this.setState({is_selected: false})
        //     }
        //     else{
        //         this.props.gotoChat(id);
        //     }
        // }
        return(
            <li style={{backgroundColor: isonhandle? "yellow":"white"}}
                onMouseEnter={this.handleMouse(true)}
                onMouseLeave={this.handleMouse(false)}>
                <button className="btn btn-gotochat"
                        onClick={this.handleClick(id)}
                        style={{backgroundColor: is_selected? "#ddd": "white"}}>
                    {/*<img src={touxiang_path} />*/}
                    {id}
                </button>
            </li>
        )
    }
}



